/**
 * @Author bian
 * @CreateDate 2017.3.2
 *
 * 验证操作集
 */
var userCache = require("../lib/cache")("IMoocUser")
var adminCache = require("../lib/cache")("IMoocAdmin")

const util = require('util')

module.exports = {
    user: function* (ctx) {
        var session = ctx.cookies.get("session")
        if(util.isNullOrUndefined(session)){
            return null
        }
        return userCache.jget(session)
    },

    // 得到admin对象
    admin: function* (ctx) {
        var session = ctx.cookies.get("session")
        if(util.isNullOrUndefined(session)){
            return null
        }
        return adminCache.jget(session)
    },

    login: (user,session,cacheKind) => {
        var cache = cacheKind == "adminCache" ? adminCache :
            cacheKind == "userCache" ? userCache : null
        cache.jsetex(session,2 *  60 * 60,user);   // 设置两小时后失效
    }
}